package tp2;

import java.util.Observable;

public class Kart extends Observable implements Runnable {
	
	private boolean running;
	private String nom;
	private int distance;
	private int distance_parcouru;
	

	public Kart(String nom, int distance, int distance_parcouru) {
		super();
		this.nom = nom;
		this.distance = distance;
		this.distance_parcouru = distance_parcouru;
		this.running = true;
	}


	public String getNom() {
		return nom;
	}


	public void setNom(String nom) {
		this.nom = nom;
	}


	public int getDistance() {
		return distance;
	}


	public void setDistance(int distance) {
		this.distance = distance;
	}


	public int getDistance_parcouru() {
		return distance_parcouru;
	}


	public void setDistance_parcouru(int distance_parcouru) {
		this.distance_parcouru = distance_parcouru;
	}


	@Override
	public void run() {
		boolean arrived = false;
		while (running && !arrived) {

			try {
				Thread.sleep((long)Math.random()*100);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			distance_parcouru++;
			arrived = distance_parcouru >= distance;
			
		}
		running = false;
		setChanged();
		notifyObservers();
		System.out.println(nom + " : "+ distance_parcouru + " : arrived : "+arrived);
	}


	public boolean isRunning() {
		return running;
	}


	public void setRunning(boolean running) {
		this.running = running;
	}
	
}
